package it.polimi.entities;

import java.io.Serializable;

import javax.persistence.*;

import java.util.List;

import it.polimi.authentication.ejb.usermanagement.*;
import it.polimi.entitiesDTO.AirportDTO;

/**
 * The persistent class for the airport database table.
 * 
 */
@Entity
@NamedQueries ({ @NamedQuery(name=Airport.FIND_ALL, query="SELECT a FROM Airport a"),
				 @NamedQuery(name=Airport.FIND_AIRPORT, query="SELECT a FROM Airport a WHERE a.name = :name"),
				 @NamedQuery(name=Airport.FIND_AIRPORT_BY_CITY, query="SELECT a FROM Airport a WHERE a.city = :city")

})

public class Airport implements Serializable {
	private static final long serialVersionUID = 1L;
	
	public static final String FIND_ALL = "Airport.findAll";
	
	public static final String FIND_AIRPORT = "Airport.findAirport";

	public static final String FIND_AIRPORT_BY_CITY = "Airport.findAirportByCity";
	
	@Id
	private String name;

	private String city;

	//bi-directional many-to-one association to Flight
	@OneToMany(mappedBy="airport1")
	private List<Flight> flights1;

	//bi-directional many-to-one association to Flight
	@OneToMany(mappedBy="airport2")
	private List<Flight> flights2;

	public Airport() {
		super();
	}
	
	public Airport(AirportDTO airport){
		this.city=airport.getCity();
		this.name=airport.getName();
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getCity() {
		return this.city;
	}

	public void setCity(String city) {
		this.city = city;
	}

	public List<Flight> getFlights1() {
		return this.flights1;
	}

	public void setFlights1(List<Flight> flights1) {
		this.flights1 = flights1;
	}

	public Flight addFlights1(Flight flights1) {
		getFlights1().add(flights1);
		flights1.setAirport1(this);

		return flights1;
	}

	public Flight removeFlights1(Flight flights1) {
		getFlights1().remove(flights1);
		flights1.setAirport1(null);

		return flights1;
	}

	public List<Flight> getFlights2() {
		return this.flights2;
	}

	public void setFlights2(List<Flight> flights2) {
		this.flights2 = flights2;
	}

	public Flight addFlights2(Flight flights2) {
		getFlights2().add(flights2);
		flights2.setAirport2(this);

		return flights2;
	}

	public Flight removeFlights2(Flight flights2) {
		getFlights2().remove(flights2);
		flights2.setAirport2(null);

		return flights2;
	}
	public String toString(){
		return "City: "+ this.getCity() +"Name: " + this.getName();
	}
}